package com.example.myapplication;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MoreInformation extends AppCompatActivity {
    private LinearLayout lv_sex, lv_region, lv_Personal_signature;
    private TextView tv_sex, tv_region, tv_Personal_signature;

    private int singleSelectedId = -1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_more_information);
        initView();
        setListener();

    }

    private void setListener() {
//        性别设置
        lv_sex.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertDialog.Builder builder = new AlertDialog.Builder(MoreInformation.this)
                        .setTitle("选择性别")
                        .setIcon(R.mipmap.xingbie)
                        .setSingleChoiceItems(new String[]{"男", "女"}, 0, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                singleSelectedId = i;
                            }
                        })
                        .setNegativeButton("取消", null)
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                if (singleSelectedId == 0) {
                                    tv_sex.setText("男");
                                } else {
                                    tv_sex.setText("女");
                                }
                            }
                        });
                builder.create().show();
            }
        });
//改变地区
        lv_region.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final View dialogview = LayoutInflater.from(MoreInformation.this).inflate(R.layout.dialog_customize, null);
                AlertDialog.Builder builder = new AlertDialog.Builder(MoreInformation.this)
                        .setTitle("更改地区")
                        .setIcon(R.mipmap.diqu)
                        .setView(dialogview)
                        .setNegativeButton("取消", null)
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                EditText edit_dialog = dialogview.findViewById(R.id.edit_dialog);
                                tv_region.setText(edit_dialog.getText().toString());
                            }
                        });
                builder.create().show();

            }
        });
        //更改个性签名
        lv_Personal_signature.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final View dialogview = LayoutInflater.from(MoreInformation.this).inflate(R.layout.dialog_customize, null);
                AlertDialog.Builder builder = new AlertDialog.Builder(MoreInformation.this)
                        .setTitle("个性签名")
                        .setIcon(R.mipmap.bi)
                        .setView(dialogview)
                        .setNegativeButton("取消", null)
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                EditText edit_dialog = dialogview.findViewById(R.id.edit_dialog);
                                tv_Personal_signature.setText(edit_dialog.getText().toString());
                            }
                        });
                builder.create().show();

            }
        });
    }

    private void initView() {
        lv_sex = findViewById(R.id.lv_sex);
        lv_region = findViewById(R.id.lv_region);
        lv_Personal_signature = findViewById(R.id.lv_Personal_signature);
        tv_sex = findViewById(R.id.tv_sex);
        tv_region = findViewById(R.id.tv_region);
        tv_Personal_signature = findViewById(R.id.tv_Personal_signature);

    }
}